﻿$(document).on('pageinit', '#county', function (e) {
    if (e.handled != true) {

        // Get county from Local Storage
        var currentCounty = GetQueryString('countyparm').toLowerCase();

        // Get Type of Location from Local Storage
        var locationType = GetQueryString("LocationType");


        // Load page header and footer
        $("#countyHeader").load('shared/header.html', function () {
            $(this).trigger('create');
        });
        $("#countyFooter").load('shared/footer.html', function () {
            $(this).trigger('create');
        });


        //$("#countySearchDiv").load('shared/search.html', function () {
        //    $(this).trigger('create');
        //});

        var locationTypeDataSource = null;
        var locationTypeURL = null;
        switch (locationType) {
            case "DL":
                locationTypeDataSource = "LocationsDL";
                locationTypeURL = "api/location/1";
                break;
            case "TR":
                locationTypeDataSource = "LocationsTR";
                locationTypeURL = "api/location/2";
                break;
            default:
                break;
        }

        // Update location count data for counties
        $.when(GetCachedItem(locationTypeDataSource, serviceURL + locationTypeURL)).done(function (a1) {
            // the code here will be executed when all four ajax requests resolve.
            // a1, a2, a3 and a4 are lists of length 3 containing the response text,
            // status, and jqXHR object for each of the four ajax calls respectively.
            //alert("aftercall  " + a1);
            $.each(a1, function (key, value) {
                if (value.County.toLowerCase() == currentCounty) {
                    $('#officelist').append("<li><a href='office.html' onclick='SaveQueryString(\"countyidparm\", \"" + value.LocationID + "\")'><img src=\"" + value.StreetViewURL + "\"' height='80px' width='80px' /><h6 class='wrap'>" + value.LocationName + "</h6><p class='wrap'>" + value.Address + ", " + value.City +"</p></a></li>").listview('refresh'); //.listview('refresh');
                }
            });
        });



        e.handled = true;
    }
});



// Full screen code
$(document).on("pagecontainertransition", function () {
    alert("pagecontainertransition");
    FullScreenAdjust();
});

$(window).on("resize", function () {
    alert("resize");
    FullScreenAdjust();
});

$(window).on("orientationchange", function () {
    alert("orientationchange");
    FullScreenAdjust();
});


function FullScreenAdjust() {
    var screen = $.mobile.getScreenHeight(),
        header = $(".ui-header").hasClass("ui-header-fixed") ? $(".ui-header").outerHeight() - 1 : $(".ui-header").outerHeight(),
        footer = $(".ui-footer").hasClass("ui-footer-fixed") ? $(".ui-footer").outerHeight() - 1 : $(".ui-footer").outerHeight(),
        contentCurrent = $(".ui-content").outerHeight() - $(".ui-content").height(),
        content = screen - header - footer - contentCurrent;
    $(".ui-content").height(content);
}